import { Action } from "~/rest";
import { ContactGateway, ContactGroupGateway } from "./dto.contact";
import { Contact, ContactGroup } from "./schema.contact";
import { INTEGER_PG } from "~/db.pg";

export const ContactRpcGetHighestGroupSyncPath = `${ContactGroupGateway.path}/getHighestGroupSync`;
export const ContactRpcInsertOnePath = `${ContactGateway.path}/putOneSync`;
export type putOneContactSyncRpcDto = { groupId: ContactGroup["id"]; schema: Contact };

export const ContactRpcFindOneByIdPath = `${ContactGateway.path}/findOne`;
export type findOneContactByIdRpcDto = { id: Contact["id"] };

export const ContactRpcFindManyByIdPath = `${ContactGateway.path}/findMany`;
export type findManyContactRpcDto = { ids: INTEGER_PG[] };

export interface ContactRpcInterfaceWithDerive<T> {
  /** 获取主账号权重最高的集合 */
  getHighestGroupSync(dto: T): Promise<{ group: ContactGroup }>;

  /** 只要名称不为空，一定会成功 */
  putOneSync(dto: T & putOneContactSyncRpcDto): Promise<Action<Contact>>;

  /** 找不到会报错 */
  findOne(dto: T & findOneContactByIdRpcDto): Promise<Contact>;
  findMany(dto: T & findManyContactRpcDto): Promise<Contact[]>;
}
